﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TruckWatch.Cloud.Models.EF;
using TruckWatch.Cloud.BusinessLogic;
using Mvc30WebRole1.Util;

namespace Mvc30WebRole1.Controllers
{
    public class LocationController : Controller
    {

        public ActionResult ListLocations()
        {
            List<Location> locations = CacheUtility.GetFromCacheOrAdd<List<Location>>("AllLocations", LocationBL.GetAllLocations);
            return View(locations);
        }

        [HttpPost]
        public ActionResult UpdateLocation(Location location)
        {
            LocationBL.UpldateLocation(location);

            CacheUtility.RemoveAllFromCache();

            return RedirectToAction("ListLocations");
        }

        [HttpPost]
        public ActionResult AddLocation(Location location)
        {
            LocationBL.AddLocation(location);
            CacheUtility.RemoveAllFromCache();

            return RedirectToAction("ListLocations");
        }

        [HttpPost]
        public ActionResult DeleteLocation(Location location)
        {
            LocationBL.DeleteLocation(location);
            CacheUtility.RemoveAllFromCache();

            return RedirectToAction("ListLocations");
        }
    }
}
